<!-- 同类商品推荐组件 -->
<template>
  <div class="goods-relevant">
    <div class="header">
      <i class="icon" />
      <span class="title">{{goodsId?'同类商品推荐': '猜你喜欢'}}</span>
    </div>
    <!-- 此处使用改造后的xtx-carousel.vue -->
    <!-- 列表轮播图 -->
    <XtxCarousel :sliders="sliders" style="height: 380px" auto-play/>
  </div>
</template>

<script>
import {ref} from 'vue'
import {findRelGoods} from '@/api/product'
//获取同类商品推荐数据
const useRelGoods = (id) => {
          const sliders = ref([])
          findRelGoods(id).then(data => {
            const pagesize = 4
            const pageTotal = Math.ceil(data.result.length / pagesize)
            for (let i = 0; i < pageTotal ; i++) {
              sliders.value.push(data.result.slice(i * pagesize, (i + 1) * pagesize))
            }
          })
          return sliders
    }
export default {
  // 同类推荐，猜你喜欢
  name: 'GoodsRelevant',
  props: {
    goodsId: {
      type: String,
      default: undefined
    }
  },
  setup (props) {
    const sliders = useRelGoods(props.goodsId)
    return {sliders}
  }
}
</script>

<style scoped lang='less'>
.goods-relevant {
  background: #fff;
  min-height: 460px;
  margin-top: 20px;
  .header {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;
    .title {
      font-size: 20px;
      padding-left: 10px;
    }
    .icon {
      width: 16px;
      height: 16px;
      display: inline-block;
      border-top: 4px solid @xtxColor;
      border-right: 4px solid @xtxColor;
      box-sizing: border-box;
      position: relative;
      transform: rotate(45deg);
      &::before {
        content: "";
        width: 10px;
        height: 10px;
        position: absolute;
        left: 0;
        top: 2px;
        background: lighten(@xtxColor, 40%);
      }
    }
  }
}
// vue3.0使用深度作用选择器写法 :deep(选择器)
:deep(.xtx-carousel) {
  height: 380px;
  .carousel {
    &-indicator {
      bottom: 30px;
      span {
        &.active {
          background: @xtxColor;
        }
      }
    }
    &-btn {
      top: 110px;
      opacity: 1;
      background: rgba(0,0,0,0);
      color: #ddd;
      i {
        font-size: 30px;
      }
    }
  }
}
</style>
  